/*
* The shader code below is licensed under the Creative Commons Attribution-Share Alike 3.0 
* license.
*
* You are free:
*	To Share: to copy, distribute, display, and perform the work
*	To Remix: to make derivative works 
*
*	Under the following conditions:
*		* Attribution - You must attribute the work in the manner specified by the author or
*			licensor (but not in any way that suggests that they endorse you or your use of the work).
*		* Share Alike - If you alter, transform, or build upon this work, you may distribute
*			the resulting work only under the same, similar or a compatible license.
*
*		For any reuse or distribution, you must make clear to others the license terms of this work.
*		The best way to do this is with a link to the above web page (http;//www.tesla-engine.net)
*
*		Any of the above conditions can be waived if you get permission from the copyright holder.
*
*		Apart from the remix rights granted under this license, nothing in this license impairs or
*		restricts the author's moral rights.
*/

#include "Structures.fxh"

uniform float4x4 WVP;
uniform float4 DiffuseColor = { 1.0f, 1.0f, 1.0f, 1.0f };

uniform texture2D DiffuseMap;
uniform sampler2D DiffuseMapSampler = 
sampler_state {
  Texture = <DiffuseMap>;
  MipFilter = LINEAR;
  MinFilter = LINEAR;
  MagFilter = LINEAR;
	AddressU = Wrap;
	AddressV = Wrap;
};

//
// **** BasicColor ****
//

float4 VS_Basic(float3 Position : POSITION) : SV_POSITION {
	return mul(float4(Position, 1.0), WVP);
}

float4 PS_Basic() : SV_TARGET {
	return DiffuseColor;
}

technique BasicColor {
	pass Pass0 {
    VertexShader = compile vs_2_0 VS_Basic();
    PixelShader = compile ps_2_0 PS_Basic();
	}
}

//
// **** BasicVertColor ****
//

VSOutputVc VS_BasicVc(VSInputVc input) {
	VSOutputVc output;
	output.PositionPS = mul(float4(input.Position, 1.0), WVP);
	output.VertColor = input.VertColor;
	return output;
}

float4 PS_BasicVc(VSOutputVc input) : SV_TARGET {
	return DiffuseColor * input.VertColor;
}

technique BasicVertColor {
	pass Pass0 {
    VertexShader = compile vs_2_0 VS_BasicVc();
    PixelShader = compile ps_2_0 PS_BasicVc();
	}
}

//
// **** BasicTexture ****
//

VSOutputTx VS_BasicTx(VSInputTx input) {
	VSOutputTx output;
	output.PositionPS = mul(float4(input.Position, 1.0), WVP);
	output.TexCoord = input.TexCoord;
	return output;
}

float4 PS_BasicTx(VSOutputTx input) : SV_TARGET {
	float4 albedo = tex2D(DiffuseMapSampler, input.TexCoord);
	return albedo * DiffuseColor;
}

technique BasicTexture {
	pass Pass0 {
    VertexShader = compile vs_2_0 VS_BasicTx();
    PixelShader = compile ps_2_0 PS_BasicTx();
	}
}

//
// **** BasicVertColorTexture ****
//

VSOutputVcTx VS_BasicVcTx(VSInputVcTx input) {
	VSOutputVcTx output;
	output.PositionPS = mul(float4(input.Position, 1.0), WVP);
	output.VertColor = input.VertColor;
	output.TexCoord = input.TexCoord;
	return output;
}

float4 PS_BasicVcTx(VSOutputVcTx input) : SV_TARGET {
	float4 albedo = tex2D(DiffuseMapSampler, input.TexCoord);
	return albedo * DiffuseColor * input.VertColor;
}

technique BasicVertColorTexture {
	pass Pass0 {
    VertexShader = compile vs_2_0 VS_BasicVcTx();
    PixelShader = compile ps_2_0 PS_BasicVcTx();
	}
}